package com.project.service.impl;

import com.project.bean.UserBean;
import com.project.mapper.IUserMapper;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.swing.*;
import java.util.List;
@Service
@Transactional
public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserMapper userMapper;

    @Override
    public UserBean login(String account, String pwd) {
        UserBean user= userMapper.login(account,pwd);
        if (user==null){
            JOptionPane.showMessageDialog(null,"账号或密码错误");
            return null;
        }
        return user;
    }

    @Override
    public List<UserBean> findByItem(String grade) {
        return userMapper.findByItem(grade);
    }

    @Override
    public void addUser(UserBean user) {
        userMapper.addUser(user);
    }

    @Override
    public void delUser(int id) {
        userMapper.delUser(id);
    }

    @Override
    public void updateGrade(int id, String grade) {
        userMapper.updateGrade(id, grade);
    }

    @Override
    public UserBean findByID(int id) {
        return userMapper.findByID(id);
    }

    @Override
    public void updatePwd(int id, String oldPwd, String newPwd, String pwd) {
        if (userMapper.verifyPwd(id,oldPwd)==null){
            System.out.println("旧密码错误");
            return;
        }
        if (newPwd!=null && !newPwd.equals(pwd)){
            return;
        }
        userMapper.updatePwd(id, newPwd);
    }


}
